package dto

import (
	"danmu/model"
)

type UserDto struct {
	Uid uint `json:"Uid"`
	Name string `json:"Name"`
	Sign string `json:"Sign"`
	Face string `json:"Face"`
}

type UserListDto struct {
	Uid uint `json:"uid"`
	Name string `json:"name"`
	Email string `json:"email"`
	Sign string `json:"sign"`
	Face string `json:"face"`
	IsAdmin int `json:"admin"`
}

type UserSearchDto struct {
	Uid uint `json:"Uid"`
	Name string `json:"Name"`
	Sign string `json:"Sign"`
	Face string `json:"Face"`
}


func ToUserDto(user model.User) UserDto {
	return UserDto{
		Uid:user.ID,
		Name:user.Name,
		Sign:user.Sign,
		Face:user.Face,
	}
}

func ToUserListDto(users []model.User) []UserListDto {
	newUserList := make([]UserListDto, len(users))
	for i:=0;i<len(users);i++{
		newUserList[i].Uid = users[i].ID
		newUserList[i].Name = users[i].Name
		newUserList[i].Email = users[i].Email
		newUserList[i].Sign = users[i].Sign
		newUserList[i].Face = users[i].Face
		newUserList[i].IsAdmin = users[i].IsAdmin
	}
	return newUserList
}

func ToUserSearchDto(users []model.User) []UserSearchDto {
	newUserList := make([]UserSearchDto, len(users))
	for i:=0;i<len(users);i++{
		newUserList[i].Uid = users[i].ID
		newUserList[i].Name = users[i].Name
		newUserList[i].Sign = users[i].Sign
		newUserList[i].Face = users[i].Face
	}
	return newUserList
}